<template>
  <div>
    <div class="title">
      <span>全部账单</span>
      
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
          <div class="leftitem">
            <!-- <div class="block">
              <el-date-picker v-model="storesinfo.stardate" type="datetime" placeholder="提交起始时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
              <el-date-picker v-model="storesinfo.enddate" type="datetime" placeholder="提交结束时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </div> -->
             <div class="block">
              <el-date-picker
                v-model="date"
                type="datetimerange"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </div>
          </div>
          <div class="leftitem">
              <el-select v-model="storesinfo.payStatusCode" placeholder="订单状态">
                <el-option key="ccc" label="已还款" value="2"></el-option>
                <el-option key="zzz" label="未还款" value="1"></el-option>
              </el-select>
              <el-input class="merchants" v-model.trim="storesinfo.totalFeenum"  @keyup.enter.native='soso' @input='totalFeenum()' placeholder="交易金额"></el-input>元
          </div>
          <!-- <div class="leftitem">
              <el-input class="servicename" v-model.trim="storesinfo.merchantId"  @keyup.enter.native='soso' placeholder="商户简称/商户号"></el-input>
          </div> -->
        </div>
        <div class="rightBox">
           <div class="rightitem">
              <el-input class="servicename" v-model.trim="storesinfo.rentNo"  @keyup.enter.native='soso' placeholder="租赁订单号"></el-input>
          </div>
          <div class="rightitem">
              <el-input class="servicename" v-model.trim="storesinfo.rentTradeNo"  @keyup.enter.native='soso' placeholder="租赁账单号"></el-input>
          </div>
          <div class="rightitem">
              <el-input class="servicename" v-model.trim="storesinfo.repayTradeNo"  @keyup.enter.native='soso' placeholder="官方订单号"></el-input>
          </div>
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso">搜索</el-button>
            <el-button icon="el-icon-refresh" type="primary" @click="reset">重置</el-button>
          </div>
        </div>
      </div>
      
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
          v-loading="loading"
        >

          <el-table-column prop="createTime" align="center" label="生成时间"></el-table-column>
          <el-table-column prop="totalFee" align="center" label="交易金额">
              <template slot-scope="scope">
                <div>￥{{scope.row.totalFee/100}}</div>
            </template>
          </el-table-column>
          <el-table-column prop="payerUserId" align="center" label="付款用户"></el-table-column>
          <!-- <el-table-column prop="merchantShortName" align="center" label="来源"></el-table-column> -->
          <el-table-column prop="rentTradeNo" align="center" label="租赁账单号"></el-table-column>
          <el-table-column prop="rentNo" align="center" label="租赁订单号"></el-table-column>
          <el-table-column prop="repayTradeNo" align="center" label="官方订单号"></el-table-column>
          <el-table-column prop="payStatusCode" align="center" label="订单状态">
            <template slot-scope="scope">
                <div type="text" class="red" size="small" v-if="scope.row.payStatusCode == 1">未还款</div>
                <div type="text" class="green" size="small" v-if="scope.row.payStatusCode == 2">已还款</div>
            </template>
          </el-table-column>
          
          <el-table-column fixed="right" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="jumporderdetails(scope.row.id)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="combined"
            :current-page.sync="cur_page"
          ></el-pagination>
        </div>
      </div>
      <br>
      <br>
     
    </div>
  </div>
</template>

<script>
import {rentTradepage} from "@/api/api";
export default {
  name: "baseform",
  data: function() {
    return {
      cur_page: 1,
      cur_size: 10,
      loading: true,
      multipleSelection: [],
      merchantarr:[],
      pageCount:"",
      date:"",
      userinfo:"",
     
      combined:0,
      storesinfo:{
        stardate:"",
        enddate:"",
        totalFee:'',
        totalFeenum:'',
        rentNo:'',
        rentTradeNo:'',
        repayTradeNo:''
      },
    };
  },
  created() {
    this.userinfo = JSON.parse(sessionStorage.getItem('userInfo'))
    this.rentTradepage()
  },
  mounted() {
  
  },
  methods: {
     //修改thead 背景色
     tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return 'background-color: #F0F0F0;font-weight: 500;font-size:14px;color:#000;'
      }
    },
    onSubmit() {
      this.$message.success("提交成功！");
    },
    renderheader(h, { column, $index }) {
      return h("span", {}, [
        h("span", {}, column.label.split("?")[0]),
        h("br"),
        h("span", {}, column.label.split("?")[1])
      ]);
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.rentTradepage()
       this.$nextTick(() => {
         document.querySelectorAll('.content')[0].scrollTop = '0'
      });
    },
     // 分页数量
    sizechange(val){
      this.cur_size = val
      this.rentTradepage()
       
       this.$nextTick(() => {
         document.querySelectorAll('.content')[0].scrollTop = '0'
      });
       
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 列表
    rentTradepage(){
       rentTradepage({
          page: this.cur_page,
          size: this.cur_size,
          merchantId: this.userinfo.fid,
          startDate: this.date[0],
          endDate: this.date[1],
          payStatusCode: this.storesinfo.payStatusCode,
          rentNo: this.storesinfo.rentNo,
          totalFee: this.storesinfo.totalFee,
          repayTradeNo:this.storesinfo.repayTradeNo,
          rentTradeNo: this.storesinfo.rentTradeNo
        }).then(res => {
          // console.log(res);
          if(res.code == 405){
            sessionStorage. removeItem('token')
            this.$router.push('/login');
          }else{
            this.merchantarr = res.data
            this.combined = res.pageInfo.recordCount
            this.pageCount = res.pageInfo.pageCount
            this.loading = false
          }
        });
    },
    // 搜索
    soso(){
      this.loading =true;
      this.cur_page = 1
      this.rentTradepage()
    },
    // 重置
    reset(){
      this.storesinfo = {
        stardate:"",
        enddate:"",
        totalFee:'',
        totalFeenum:'',
        rentNo:'',
        rentTradeNo:'',
        repayTradeNo:''
      }
      this.date = ''
    },
    // 刷新
    refresh (){
      // this.$router.replace({
      //   path: '/refresh',
      //   query: {
      //     t: Date.now()
      //   }
      // })
       this.loading = true
       this.reset()
       this.rentTradepage()
    },
     // 跳详情
    jumporderdetails(val){
      this.$router.push({path:'/orderdetails',query:{id:val}})
    },
    //监听交易金额
    totalFeenum(){
      if(!this.storesinfo.totalFeenum){
        this.storesinfo.totalFee = ''
      }else{
        this.storesinfo.totalFee = this.storesinfo.totalFeenum*100
      }
     
    },
  }
};
</script>
<style scoped lang="less">
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 30%;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #374459;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
}
.statistical > .statisticalitem {
  width: 50%;
  text-align: center;
  line-height: 200%;
}
.tableBox {
  margin-top: 20px;
}

.red {
  color: #f9607d !important;
}
.green{
    color: green !important;
}
.my-autocomplete {
  li {
    line-height: normal;
    padding: 7px;

    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
.servicename{
  width: 50%;
}
</style>